package com.api.shopapi.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.entity.EElderlyHelp;
import com.api.shopapi.mapper.EElderlyHelpMapper;
import com.api.shopapi.service.EElderlyHelpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service("EElderlyHelpServiceImplOne")
public class EElderlyHelpServiceImpl implements EElderlyHelpService {

    @Autowired
    private EElderlyHelpMapper elderlyHelpMapper;



    @Override
    @Transactional
    public int insert(EElderlyHelp elderlyHelp) {
        return elderlyHelpMapper.insert(elderlyHelp);
    }

    @Override
    public int update(EElderlyHelp elderlyHelp) {
        return elderlyHelpMapper.update(elderlyHelp);
    }

    @Override
    public int delete(String elderlyHelpCode) {
        return elderlyHelpMapper.delete(elderlyHelpCode);
    }

    @Override
    public EElderlyHelp getByElderlyHelpCode(String elderlyHelpCode) {
        return elderlyHelpMapper.getByElderlyHelpCode(elderlyHelpCode);
    }

    @Override
    public List<EElderlyHelp> getListByElderlyCode(String elderlyCode) {
        return elderlyHelpMapper.getListByElderlyCode(elderlyCode);
    }

    @Override
    public PageInfo<EElderlyHelp> getPageListByElderlyCode(int pageIndex, int pageSize, String elderlyCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<EElderlyHelp> elderlyHelpList = elderlyHelpMapper.getListByElderlyCode(elderlyCode);
        return new PageInfo<>(elderlyHelpList);
    }

    @Override
    @Transactional
    public void deleteAll(JSONArray elderlyHelpCodeList) {
        for (int i=0;i<elderlyHelpCodeList.size();i++){
            elderlyHelpMapper.delete(elderlyHelpCodeList.get(i).toString());
        }
    }
}
